package cn.lsh.kafka.db.service;

import org.apache.ibatis.session.SqlSession;

public abstract class BaseService<T> {

	protected SqlSession sqlSession;
	/** 泛型T为实体的Mapper类 */
	protected T mapper;

	public BaseService(SqlSession sqlSession) {
		//为service装载sqlSession
		this.sqlSession = sqlSession;
	}

	protected void commit() {
		this.sqlSession.commit();
	}

	protected void close() {
		//private不能被子类继承，protect可以被子类继承，但是不能被反射出来
		this.close();
	}

	public void setMapper(Class<T> t) {
		try {
			this.mapper = this.sqlSession.getMapper(t);
		} catch (Exception e) {
			this.sqlSession.getConfiguration().addMapper(t);
			this.mapper = sqlSession.getMapper(t);
		}
	}
}
